using B.S.Data.MES.API.Applications.CangKu.Command;
using B.S.Domain.CangKu;
using B.S.Infratrctrue;
using B.S.Requst;
using MediatR;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace B.S.Data.MES.API.Applications.CangKu.CommandHandlers
{
    public class PLDeleCangKuCommandHandler : IRequestHandler<PLDeleCangKuCommand, APIRequst<int>>
    {
        private readonly IBaseRepository<CangKuinfo> _cangKuRepository;

        public PLDeleCangKuCommandHandler(IBaseRepository<CangKuinfo> cangKuRepository)
        {
            _cangKuRepository = cangKuRepository;
        }

        public async Task<APIRequst<int>> Handle(PLDeleCangKuCommand request, CancellationToken cancellationToken)
        {
            APIRequst<int> requst = new APIRequst<int>();
            requst.Code = RequstCode.成功;
            var path = _cangKuRepository.GetAll().Where(o => request.Ids.Contains(o.CangId)).ToList();
            foreach (var item in path)
            {
                item.isDel = true;
            }
            await _cangKuRepository.UpdateRange(path);
            return await Task.FromResult(requst);
        }
    }
}